package com.sbio.udiapp.util;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;

import com.sbio.udiapp.receiver.AlarmReceiver;

import java.io.File;

public class MyAlarmManager {
    private static final String TAG = "MyAlarmManager";

    public static void setRepeatingAlarm(Context context) {
        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, AlarmReceiver.class);
        PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);

        // 设置每小时触发一次
        long intervalMillis = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
        long triggerAtMillis = SystemClock.elapsedRealtime() + intervalMillis;

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis, intervalMillis, alarmIntent);
        Log.d(TAG, "Repeating alarm set");
    }
}
